/**
 * Created by Blink on 2017/8/18.
 * icon text
 */

import React from 'react';
import {StyleSheet, Text} from 'react-native';
import ComponentBase from '../component.base';
import BlinkText from './text';
import Maps from '../../icon.maps';

export default class BlinkIcon extends BlinkText {
    static propTypes = {
        ...BlinkText.propTypes,
        name: checkIconName
    };

    static defaultProps = {
        ...BlinkText.defaultProps,
        size: 24,
        name: 'photo'
    };

    render() {
        const {style, children, color, name, size, ...other} = this.props;

        return <Text {...other}
                     style={[
                         this._color,
                         {fontSize: size},
                         style,
                         _css.icon,
                     ]
                     }>{Maps[name]}</Text>
    }
}

function checkIconName(props, propName) {
    const name = propName[props];

    if (name && !Maps.hasOwnProperty(name)) {
        return new Error('unknow icon name "' + name + '". check icon.maps.js');
    }
}

const _css = StyleSheet.create({
    icon: {
        fontFamily: 'blinkIcon',
        fontWeight: 'normal'
    }
});